package com.hy.mvc.biz.service.manager.base;

import com.github.pagehelper.PageHelper;
import com.hy.mvc.biz.service.mapper.IMapper;
import com.hy.mvc.domain.dataobject.base.BaseDO;
import com.hy.mvc.domain.dataobject.base.PageDO;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <pre>
 *    author  : Booker
 *    time    : 2017/12/6 14:59
 *    desc    : 输入描述
 *    version : v1.0
 * </pre>
 */
public abstract class PageManager<T extends BaseDO, E, S extends IMapper<T, E>> {

    @Autowired
    protected S mapper;

    public PageDO<T> queryPage(E exampleObject, int start, int count) {
        com.github.pagehelper.Page pp = PageHelper.startPage((start + count) / count, count);
        List<T> list = this.mapper.selectByExampleWithRowbounds(exampleObject, new RowBounds(start, count));
        PageDO page = new PageDO();
        page.setTotalItem((int)pp.getTotal());
        page.setData(list);
        PageHelper.clearPage();
        return page;
    }

}
